﻿using EFEntity;
using Iservices;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Services
{
  public  class config_majorServices:Iconfig_majorServices
    {
        private readonly MyDbContext myDBContext;

        public config_majorServices(MyDbContext myDBContext)
        {
            this.myDBContext = myDBContext;
        }
        //查看全部
        public async Task<List<config_major>> config_majorSelect()
        {
            List<Econfig_major> list = new List<Econfig_major>();
            await Task.Run(() =>
            {
                list = myDBContext.config_major.ToList();
            });

            //Automap
            List<config_major> list2 = new List<config_major>();
            foreach (Econfig_major item in list)
            {
                config_major t = new config_major()
                {
                    mak_id = item.mak_id,
                    major_kind_id = item.major_kind_id,
                    major_kind_name = item.major_kind_name,
                    major_id=item.major_id,
                    major_name=item.major_name,
                    test_amount =item.test_amount
                };
                list2.Add(t);
            }
            return list2;
        }

        public async Task<List<config_major>> Getmajor(string ids)
        {
            List<Econfig_major> elist = new List<Econfig_major>();
            List<config_major> list = new List<config_major>();
            await Task.Run(() =>
            {
                elist = (from e in myDBContext.config_major
                         where e.major_kind_id == ids
                         select e).ToList();
                foreach (Econfig_major item in elist)
                {
                    config_major config = new config_major()
                    {
                        mak_id = item.mak_id,
                        major_kind_id = item.major_kind_id,
                        major_kind_name = item.major_kind_name,
                        major_id = item.major_id,
                        major_name = item.major_name,
                        test_amount = item.test_amount
                    };
                    list.Add(config);
                }
            });
            return list;
        }
    }
}
